<?php

namespace App\Http\Requests;

use App\Exceptions\ApiException;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
class NewWebsiteCounselRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'city_id'=>'required',
            'area_id'=>'required',
            'name'=>'required',
            'mobile'=>'required',
            'type'=>'required'
        ];
    }
    public function messages()
    {
        return [
            'city_id.required'=>'请选择城市',
            'area_id.required'=>'请选择面积',
            'name.required'=>'请输入名称',
            'mobile.required'=>'请输入联系方式',
            'type.required'=>'请选择配盘还是放盘'
        ];
    }
    protected function failedValidation(Validator $validator) {
        $error= $validator->errors()->all();
        throw new ApiException($error[0]);
    }
}
